package com.bcu.calculus.service.serviceImpl;

import com.bcu.calculus.entity.CheckMessage;
import com.bcu.calculus.entity.CheckMessageNumber;
import com.bcu.calculus.entity.CheckType;
import com.bcu.calculus.entity.Message;
import com.bcu.calculus.mapper.CheckMessageMapper;
import com.bcu.calculus.mapper.CheckTypeMapper;
import com.bcu.calculus.service.CheckMessageService;
import com.bcu.calculus.service.CheckTypeService;
import com.bcu.calculus.utils.CheckMessageUtil;
import com.bcu.calculus.utils.SendUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.List;


@Service
public class CheckMessageServiceImpl implements CheckMessageService {

    @Resource
    private CheckMessageMapper checkMessageMapper;


    @Override
    public Message<String> insertSelective(CheckMessageNumber checkMessageNumber) throws ParseException {
        String checkMessageId = "CM" + SendUtil.genSendId();
        checkMessageNumber.setCheckMessageId(checkMessageId);
        CheckMessage checkMessage = CheckMessageUtil.change(checkMessageNumber);
        checkMessage.setCheckCreateTime(new Date());
        return checkMessageMapper.insertSelective(checkMessage)> 0 ? Message.success(null).add(checkMessageId) : Message.fail(null);
    }

    @Override
    public Message<?> deleteByPrimaryKey(String checkMessageId) {
        return checkMessageMapper.deleteByPrimaryKey(checkMessageId)> 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> updateByPrimaryKeySelective(CheckMessageNumber checkMessageNumber) throws ParseException {
        CheckMessage checkMessage = CheckMessageUtil.change(checkMessageNumber);
        return checkMessageMapper.updateByPrimaryKeySelective(checkMessage)> 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<List<CheckMessage>> selectAll() {
        return Message.success(null).add(checkMessageMapper.selectAll());
    }

    @Override
    public Message<List<CheckMessage>> selectById(String checkMessageId) {
        return Message.success(null).add(checkMessageMapper.selectById(checkMessageId));
    }

    @Override
    public Message<List<CheckMessage>> selectByAttendanceId(String checkAttendanceId) {
        return Message.success(null).add(checkMessageMapper.selectByAttendanceId(checkAttendanceId));
    }
}
